polling waiting for the device to connect and disconnect.
Signed-off-by: Ewan Mellor <ewan@xensource.com>
--- /dev/null
+#!/usr/bin/python
+
+# Copyright (c) 2006 XenSource Inc.
+# Author: Ewan Mellor <ewan@xensource.com>
+
+import time
+
+from XmTestLib import *
+
+import xen.util.blkif
+
+
+__all__ = [ "block_attach", "block_detach" ]
+
+
+def get_state(domain, devname):
+ number = xen.util.blkif.blkdev_name_to_number(devname)
+ s, o = traceCommand("xm block-list %s | awk '/^%d/ {print $4}'" %
+ (domain.getName(), number))
+ if s != 0:
+ FAIL("block-list failed")
+ if o == "":
+ return 0
+ else:
+ return int(o)
+
+
+def block_attach(domain, phy, virt):
+ status, output = traceCommand("xm block-attach %s %s %s w" %
+ (domain.getName(), phy, virt))
+ if status != 0:
+ FAIL("xm block-attach returned invalid %i != 0" % status)
+
+ for i in range(10):
+ if get_state(domain, virt) == 4:
+ break
+ time.sleep(1)
+ else:
+ FAIL("block-attach failed: device did not switch to Connected state")
+
+
+def block_detach(domain, virt):
+ status, output = traceCommand("xm block-detach %s %s" %
+ (domain.getName(), virt))
+ if status != 0:
+ FAIL("xm block-detach returned invalid %i != 0" % status)
+
+ for i in range(10):
+ if get_state(domain, virt) == 0:
+ break
+ time.sleep(1)
+ else:
+ FAIL("block-detach failed: device did not disappear")
# Copyright (C) International Business Machines Corp., 2005
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
-import sys
import re
-import time
from XmTestLib import *
+from XmTestLib.block_utils import *
if ENABLE_HVM_SUPPORT:
SKIP("Block-attach not supported for HVM domains")
FAIL(str(e))
-status, output = traceCommand("xm block-attach %s phy:ram1 sdb1 w" % domain.getName())
-if status != 0:
- FAIL("xm block-attach returned invalid %i != 0" % status)
+block_attach(domain, "phy:ram1", "sdb1")
try:
run = console.runCmd("cat /proc/partitions")
# Copyright (C) International Business Machines Corp., 2005
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
-import sys
import re
-import time
from XmTestLib import *
+from XmTestLib.block_utils import *
if ENABLE_HVM_SUPPORT:
SKIP("Block-attach not supported for HVM domains")
FAIL(str(e))
-status, output = traceCommand("xm block-attach %s file:/dev/ram1 sdb2 w" % domain.getName())
-if status != 0:
- FAIL("xm block-attach returned invalid %i != 0" % status)
+block_attach(domain, "file:/dev/ram1", "sdb2")
try:
run = console.runCmd("cat /proc/partitions")
# Copyright (C) International Business Machines Corp., 2005
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
-import sys
import re
-import time
from XmTestLib import *
# Copyright (C) International Business Machines Corp., 2005
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
-import sys
import re
-import time
from XmTestLib import *
+from XmTestLib.block_utils import *
if ENABLE_HVM_SUPPORT:
SKIP("Block-attach not supported for HVM domains")
for i in range(10):
- status, output = traceCommand("xm block-attach %s phy:ram1 sdb1 w" % domain.getName())
- if status != 0:
- FAIL("xm block-attach returned invalid %i != 0" % status)
- # verify that it comes
+ block_attach(domain, "phy:ram1", "sdb1")
run = console.runCmd("cat /proc/partitions")
if not re.search("sdb1", run["output"]):
FAIL("Failed to attach block device: /proc/partitions does not show that!")
- status, output = traceCommand("xm block-detach %s 2065" % domain.getName())
- if status != 0:
- FAIL("xm block-detach returned invalid %i != 0" % status)
- # verify that it goes
+ block_detach(domain, "sdb1")
run = console.runCmd("cat /proc/partitions")
if re.search("sdb1", run["output"]):
FAIL("Failed to dettach block device: /proc/partitions still showing that!")
# Copyright (C) International Business Machines Corp., 2005
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
-import sys
import re
-import time
from XmTestLib import *
# Copyright (C) International Business Machines Corp., 2005
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
-import sys
import re
-import time
from XmTestLib import *
# Copyright (C) International Business Machines Corp., 2005
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
-import sys
import re
-import time
from XmTestLib import *
+from XmTestLib.block_utils import *
if ENABLE_HVM_SUPPORT:
SKIP("Block-attach not supported for HVM domains")
FAIL("mke2fs returned %i != 0" % s)
for i in range(10):
- status, output = traceCommand("xm block-attach %s phy:ram1 hda1 w" % domain.getName())
- if status != 0:
- FAIL("xm block-attach returned invalid %i != 0" % status)
- # verify that it comes
+ block_attach(domain, "phy:ram1", "hda1")
run = console.runCmd("cat /proc/partitions")
if not re.search("hda1", run["output"]):
FAIL("Failed to attach block device: /proc/partitions does not show that!")
print run['output']
console.runCmd("umount /mnt/hda1")
- status, output = traceCommand("xm block-detach %s 769" % domain.getName())
- if status != 0:
- FAIL("xm block-detach returned invalid %i != 0" % status)
- # verify that it goes
+ block_detach(domain, "hda1")
run = console.runCmd("cat /proc/partitions")
if re.search("hda1", run["output"]):
FAIL("Failed to dettach block device: /proc/partitions still showing that!")
# Copyright (C) International Business Machines Corp., 2005
# Author: Murillo F. Bernardes <mfb@br.ibm.com>
-import sys
import re
-import time
import random
from xen.util import blkif
from os import path.basename
from XmTestLib import *
+from XmTestLib.block_utils import *
def availableRamdisks():
i = 0
return i
def attach(phy, devname):
- # Attach
- status, output = traceCommand("xm block-attach %s phy:%s %s w" % (domain.getName(), phy, devname))
- if status != 0:
- return -1, "xm block-attach returned invalid %i != 0" % status
-
+ block_attach(domain, "phy:%s" % phy, devname)
run = console.runCmd("cat /proc/partitions")
if not re.search(basename(devname), run["output"]):
return -2, "Failed to attach block device: /proc/partitions does not show that!"
return 0, None
-def dettach(devname):
- devnum = blkif.blkdev_name_to_number(devname)
-
- status, output = traceCommand("xm block-detach %s %d" % (domain.getName(), devnum))
- if status != 0:
- return -1, "xm block-attach returned invalid %i != 0" % status
+def detach(devname):
+ block_detach(domain, devname)
run = console.runCmd("cat /proc/partitions")
if re.search(basename(devname), run["output"]):
- return -2, "Failed to dettach block device: /proc/partitions still showing that!"
+ return -2, "Failed to detach block device: /proc/partitions still showing that!"
return 0, None
devname = random.choice(devices)
devices.remove(devname)
print "Detaching %s" % devname
- status, msg = dettach(devname)
+ status, msg = detach(devname)
if status:
FAIL(msg)
# Author: Dan Smith <danms@us.ibm.com>
from XmTestLib import *
+from XmTestLib.block_utils import block_detach
if ENABLE_HVM_SUPPORT:
SKIP("Block-detach not supported for HVM domains")
if run["return"] != 0:
FAIL("block device isn't attached; can't detach!")
-status, output = traceCommand("xm block-detach %s 769" % domain.getName(),
- logOutput=True)
-if status != 0:
- FAIL("block-detach returned invalid %i != 0" % status)
-
+block_detach(domain, "hda1")
try:
run = console.runCmd("cat /proc/partitions | grep hda1")
# Author: Dan Smith <danms@us.ibm.com>
from XmTestLib import *
+from XmTestLib.block_utils import *
if ENABLE_HVM_SUPPORT:
SKIP("Block-detach not supported for HVM domains")
print e.extra
FAIL("Unable to create domain")
-status, output = traceCommand("xm block-attach %s phy:/dev/ram0 hda1 w" % domain.getName())
-if status != 0:
- FAIL("Failed to attach block device")
- pass
-
+block_attach(domain, "phy:/dev/ram0", "hda1")
try:
run = console.runCmd("cat /proc/partitions | grep hda1")
except ConsoleError, e:
if run["return"] != 0:
FAIL("Failed to verify that block dev is attached")
-status, output = traceCommand("xm block-detach %s 769" % domain.getName())
-if status != 0:
- FAIL("block-detach returned invalid %i != 0" % status)
-
+block_detach(domain, "hda1")
try:
run = console.runCmd("cat /proc/partitions | grep hda1")
except ConsoleError, e:
# Author: Dan Smith <danms@us.ibm.com>
from XmTestLib import *
+from XmTestLib.block_utils import block_detach
if ENABLE_HVM_SUPPORT:
SKIP("Block-detach not supported for HVM domains")
if run["return"] != 0:
FAIL("block device isn't attached; can't detach!")
-status, output = traceCommand("xm block-detach %s hda1" % domain.getName(),
- logOutput=True)
-if status != 0:
- FAIL("block-detach returned invalid %i != 0" % status)
-
+block_detach(domain, "hda1")
try:
run = console.runCmd("cat /proc/partitions | grep hda1")
# Author: Dan Smith <danms@us.ibm.com>
from XmTestLib import *
+from XmTestLib.block_utils import *
-import time
import re
-def checkBlockList(domain):
- s, o = traceCommand("xm block-list %s" % domain.getName())
- if s != 0:
- FAIL("block-list failed")
- if re.search("769", o):
- return True
- else:
- return False
-
def checkXmLongList(domain):
s, o = traceCommand("xm list --long %s" % domain.getName())
if s != 0:
else:
return False
-def checkBlockState(domain):
- s, o = traceCommand("xm block-list %s | awk '{print $4}' |tail -n 1" % domain.getName())
- if s != 0:
- FAIL("block-list failed")
- return int(o)
-
if ENABLE_HVM_SUPPORT:
SKIP("Block-detach not supported for HVM domains")
except DomainError,e:
FAIL(str(e))
-s, o = traceCommand("xm block-attach %s phy:/dev/ram0 hda1 w" % domain.getName())
-if s != 0:
- FAIL("block-attach failed")
-
-if not checkBlockList(domain):
- FAIL("block-list does not show that hda1 was attached")
+block_attach(domain, "phy:/dev/ram0", "hda1")
if not checkXmLongList(domain):
FAIL("xm long list does not show that hda1 was attached")
-for i in range(1, 10):
- time.sleep(1)
- state = checkBlockState(domain)
- if state == 4:
- break
-
-s, o = traceCommand("xm block-detach %s hda1" % domain.getName())
-if s != 0:
- FAIL("block-detach failed")
-
-time.sleep(2)
-
-if checkBlockList(domain):
- FAIL("block-list does not show that hda1 was removed")
+block_detach(domain, "hda1")
if checkXmLongList(domain):
FAIL("xm long list does not show that hda1 was removed")
-
-
#!/usr/bin/python
-
+
# Copyright (C) International Business Machines Corp., 2005
# Author: Li Ge <lge@us.ibm.com)
from XmTestLib import *
+from XmTestLib.block_utils import block_attach
if ENABLE_HVM_SUPPORT:
SKIP("Block-list not supported for HVM domains")
domain = XmTestDomain()
-
+
try:
console = domain.start()
except DomainError, e:
FAIL("Unable to create domain")
#Attach one virtual block device to domainU
-status, output = traceCommand("xm block-attach %s phy:/dev/ram0 hda1 w" % domain.getId())
-if status != 0:
- FAIL("Fail to attach block device")
+block_attach(domain, "phy:/dev/ram0", "hda1")
#Verify block-list on Domain0
status, output = traceCommand("xm block-list %s" % domain.getId())
# Author: Dan Smith <danms@us.ibm.com>
from XmTestLib import *
+from XmTestLib.block_utils import *
if ENABLE_HVM_SUPPORT:
SKIP("Block-list not supported for HVM domains")
if o:
FAIL("block-list without devices reported something!")
-s, o = traceCommand("xm block-attach %s phy:/dev/ram0 hda1 w" % domain.getName())
-if s != 0:
- FAIL("Unable to attach /dev/ram0->hda1")
+block_attach(domain, "phy:/dev/ram0", "hda1")
s, o = traceCommand("xm block-list %s" % domain.getName())
if s != 0:
if o.find("769") == -1:
FAIL("block-list didn't show the block device I just attached!")
-s, o = traceCommand("xm block-attach %s phy:/dev/ram1 hda2 w" % domain.getName())
-if s != 0:
- FAIL("Unable to attach /dev/ram1->hda2")
+block_attach(domain, "phy:/dev/ram1", "hda2")
s, o = traceCommand("xm block-list %s" % domain.getName())
if s != 0:
if o.find("770") == -1:
FAIL("block-list didn't show the other block device I just attached!")
-s, o = traceCommand("xm block-detach %s 769" % domain.getName())
-if s != 0:
- FAIL("block-detach of hda1 failed")
+block_detach(domain, "hda1")
-time.sleep(1)
s, o = traceCommand("xm block-list %s" % domain.getName())
if s != 0:
FAIL("block-list failed after detaching a device")
if o.find("770") == -1:
FAIL("hda2 not shown after detach of hda1!")
-s, o = traceCommand("xm block-detach %s 770" % domain.getName())
-if s != 0:
- FAIL("block-detach of hda2 failed")
+block_detach(domain, "hda2")
-time.sleep(1)
s, o = traceCommand("xm block-list %s" % domain.getName())
if s != 0:
FAIL("block-list failed after detaching another device")